﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
using System.Xml;
using SdmxMl.SmsImportCfg;
using SdmxMl.Common;
using SdmxMl.Structure;
using SdmxMl.Manager;
using SdmxMl.GenericMetadata;

namespace SilcQuest
{
    public class SakeDsd
    {
        private SmManager sm;
        private ConceptSchemeType cst;
        private KeyFamilyType dsd;

        public void AddQualityAttributes()
        {
            sm = ReferenceManager.GetSmContainerImage();
            cst = sm.GetArtefact(SdmxArtefactType.Concepts, new ArtefactRefBase("CH1_SAKE+CS_SAKE_VAR+2012.0"), true) as ConceptSchemeType;
            dsd = sm.GetArtefact(SdmxArtefactType.KeyFamilies, new ArtefactRefBase("CH1_SAKE+DSD_SAKEQ+1.0"), true) as KeyFamilyType;

            foreach (BaseDimensionType dim in dsd.CrossSectionalMeasureList)
            {
                if (dim == dsd.PrimaryMeasure)
                    continue;
                string cid = dim.ConceptInfo.Id;
                ConceptType c = cst.ConceptList.LocateItem(cid + "_F") as ConceptType;
                if (c != null && c.Parent == cid)
                {
                    AttributeType at = new AttributeType();
                    at.ConceptInfo.Id = cid + "_F";
                    at.ConceptSchemeInfo.Id = cst.Id;
                    at.ConceptSchemeInfo.AgencyId = cst.AgencyId;
                    at.ConceptSchemeInfo.Version = cst.Version;
                    at.AttachmentLevel = AttributeType.AttachmentLevelType.Observation;
                    at.AttachmentMeasureList.Add(cid);
                    dsd.AttributeList.Add(at);

                }

            }
        }


    }
}
